package com.icoding.starter.http;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Author: LJJ
 * @Date: 2020/7/22 14:23
 * @Desc:
 */
@Configuration
@EnableConfigurationProperties(MyHttpProperties.class)
public class HttpAutoConfiguration {

    @Resource
    private MyHttpProperties properties; // 使用配置

    // 在Spring上下文中创建一个对象
    @Bean
    @ConditionalOnMissingBean
    public MyHttpClient init() {
        MyHttpClient client = new MyHttpClient();
        String url = properties.getUrl();
        client.setUrl(url);
        return client;
    }



}
